<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:c="livcos.org/ns/cosmos"
  xmlns:h="livcos.org/ns/cosmos/history"
  xmlns:f="livcos.org/ns/xslt/function"
  xmlns="http://www.w3.org/1999/xhtml"
  exclude-result-prefixes="xs c h f">
  
  <xsl:import href="./style/base.xsl"/>
  <xsl:import href="./style/view.xsl"/>
  <xsl:import href="./style/web.xsl"/>
  
  <xsl:param name="view"/>
  <xsl:variable name="scope" select="'history'"/>
  
  <xsl:template match="/*">
    <html>
      <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <link href="{$toDomainPath}/web/css/styles.css" rel="stylesheet" type="text/css"/>
        <link href="{$toDomainPath}/web/css/history.css" rel="stylesheet" type="text/css"/>
        <script type="text/javascript" src="{$toDomainPath}/web/script/E.js"><!-- --></script>
        <script type="text/javascript" src="{$toDomainPath}/web/script/util.js"><!-- --></script>
        <script type="text/javascript" src="{$toDomainPath}/web/script/init.js"><!-- --></script>
        <script type="text/javascript" src="{$toDomainPath}/web/script/history.js"><!-- --></script>
      </head>
      <body>
        <table border="0" cellspacing="0" cellpadding="0">
          <tbody>
            <tr style="height: 4%;">
              <th colspan="3">
                <span style="font-variant: small-caps;">History of </span>
                <xsl:value-of select="$absRef"/>
              </th>
            </tr>
            <tr style="height: 3%;">
              <th>Revision</th>
              <th>&#160;</th>
              <th>Revision</th>
            </tr>
            <tr style="height: 24%;">
              <td style="height: 12em;">
                <div style="overflow: auto; height: 100%;">
                  <xsl:apply-templates select="h:change">
                    <xsl:sort select="@time" order="descending"/>
                    <xsl:with-param name="side" select="1"/>
                  </xsl:apply-templates>
                </div>
              </td>
              <th>&#160;</th>
              <td style="height: 12em;">
                <div style="overflow: auto; height: 100%;">
                  <xsl:apply-templates select="h:change">
                    <xsl:sort select="@time" order="descending"/>
                    <xsl:with-param name="side" select="2"/>
                  </xsl:apply-templates>
                </div>
              </td>
            </tr>
            <tr style="height: 3%;">
              <th>Preview</th>
              <th>&#160;</th>
              <th>Preview</th>
            </tr>
            <tr style="height: 64%;">
              <td class="preview">
                <iframe id="preview1" name="preview1" marginwidth="0" marginheight="0" vspace="0" hspace="0"
                  frameborder="0"/>
              </td>
              <th style="width: 1%;">&#160;</th>
              <td class="preview">
                <iframe id="preview2" name="preview2" marginwidth="0" marginheight="0" vspace="0" hspace="0"
                  frameborder="0"/>
              </td>
            </tr>
          </tbody>
        </table>
      </body>
    </html>
  </xsl:template>
  
  <xsl:template match="@time">
    <xsl:value-of select="format-dateTime(xs:dateTime(.), '[Y0001]-[M01]-[D01]&#160;[H01]:[m01]:[s01]')"/>
  </xsl:template>
  
  <xsl:template match="h:*">
    <xsl:param name="side"/>
    <a target="preview{$side}">
      <xsl:attribute name="href">
        <xsl:choose>
          <xsl:when test="$view">
            <xsl:value-of select="$view"/>
            <xsl:value-of select="if (contains($view, '?')) then '&amp;' else '?'"/>
            <xsl:text>_rev=</xsl:text>
            <xsl:value-of select="@id"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>data?ref=</xsl:text>
            <xsl:value-of select="$ref"/>
            <xsl:text>&amp;_rev=</xsl:text>
            <xsl:value-of select="@id"/>
          </xsl:otherwise>
        </xsl:choose>
        <xsl:text>&amp;incl-editor=0</xsl:text>
      </xsl:attribute>
      <xsl:apply-templates select="@time"/>
    </a>
    <br xmlns=""/>
  </xsl:template>
  
</xsl:stylesheet>